package com.none.web.service.mycorner.impl;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.none.core.common.utils.StringUtil;
import com.none.core.exception.ValidateException;
import com.none.core.model.Pager;
import com.none.core.service.BaseServiceSupport;
import com.none.web.common.SysConstant;
import com.none.web.model.TActivity;
import com.none.web.model.TActivityImage;
import com.none.web.model.TNews;
import com.none.web.model.TNewsImage;
import com.none.web.model.TUserApp;
import com.none.web.service.comments.ICommentsService;
import com.none.web.service.logs.ILogsService;
import com.none.web.service.mycorner.IMyCornerService;

/**
 * 
 * @Description: My Corner管理Service实现
 * @author Bing
 * @date 2015年8月26日 上午10:28:53
 */
@Service("cornerService")
public class MyCornerServiceImpl extends BaseServiceSupport implements IMyCornerService {
	@Autowired
    JdbcTemplate jdbcTemplate;
	@Autowired
 	ILogsService logService;
    @Autowired
    ICommentsService commentsService;
    @Autowired
   	com.none.web.service.activity.IActivityService iActivityService;

	@SuppressWarnings("unchecked")
	@Override
	public Object getRegActivity(String userId) throws Exception {
		if (StringUtils.isBlank(userId))
			throw new ValidateException("news.notIsLoginUser");

		TUserApp appLoginUser = findEntity(TUserApp.class, userId);
		if (appLoginUser == null) {
			throw new ValidateException("user.userUnExist");
		}
		
		String sql="select distinct t.activity_id from t_activity_appuser t where t.user_id = '"+userId+"' order by t.enroll_time desc limit 3";
		List<Map<String, Object>> listMap=this.jdbcTemplate.queryForList(sql);
		List<Object> ObjectList = new ArrayList<Object>();
		if(listMap!=null && listMap.size()>0){
			for(int i=0;i<listMap.size();i++){
				TActivity act = null;
				
				String contentId = StringUtil.toString(listMap.get(i).get("activity_id"));
				
				act = findEntity(TActivity.class, contentId);
				
				if(act == null){
					continue;
				}
				
				//设置是否已经报过名
				Integer regNums = this.getRegActivityNumsById(userId, contentId);
				if(regNums>0){
					act.setRegFlag("yes");
				}else{
					act.setRegFlag("no");
				}
					
				act.setTypes("activity");
				//Add by Bing 2015-08-27  
				Criteria activityImageCriteria = getCriteria(TActivityImage.class);
				activityImageCriteria.add(Restrictions.eq("activityId", act.getId()));
				activityImageCriteria.addOrder(Order.asc("orderIndex"));
				act.setImageList(activityImageCriteria.list());
					
				act.setFlag(iActivityService.checkActivity(act.getId(), userId));
				
				String content = act.getDescription();
				if(content.contains(SysConstant.startString)&&content.contains(SysConstant.endString)){
					act.setVideoFlag("video");
				}else{
					act.setVideoFlag("notvideo");
				}
					
				//设置点赞数量   Add by Bing 2015-08-27  
				String likeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.delete_flag='0'";
				List<Map<String, Object>> listMapLike=this.jdbcTemplate.queryForList(likeSql);
				if(listMapLike!=null && listMapLike.size()>0){
					act.setLikeAmount(StringUtil.toInteger(listMapLike.get(0).get("num")));
				}else{
					act.setLikeAmount(0);
				}
					
				//设置当前用户是否对该信息点过赞  Add by Bing 2015-08-27  
				String islikeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.userId='"+userId+"' and t.delete_flag='0'";
				List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
				Integer amount=0;
				if(listMapIsLike!=null && listMapIsLike.size()>0){
					amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
				}else{
					amount=0;
				}
				if(amount>0){
					act.setLike(true);
				}else{
					act.setLike(false);
				}
					
				//设置浏览数量  Add by Bing 2015-08-27  
				act.setBrowseTimes(logService.getBrowseTimes(act.getId(), "activity", userId));
				
				//设置浏览数量(同一人浏览几次算几次)  Add by Bing 2015-08-27  
				act.setAllBrowseTimes(logService.getAllBrowseTimes(act.getId()+"", "activity", userId));
					
				//设置评论数量  Add by Bing 2015-08-27  
				act.setCommentAmount(commentsService.getCommentsAmount(act.getId()+"", "activity"));
					
				//设置Finish标志  Add by Bing 2015-08-27  
				long deadLine = act.getEndTime().getTime();
				long nowTime = new Date().getTime();
				if(nowTime>deadLine){
					act.setFinishFlag("true");
				}else{
					act.setFinishFlag("false");
				}
				
				if(act!=null){
					ObjectList.add(act);
				}
			}
		}
		return ObjectList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object getAllRegActivity(Pager pager, String userId) throws Exception {
		pager.setPageSize(10);
		if (StringUtils.isBlank(userId))
			throw new ValidateException("news.notIsLoginUser");

		TUserApp appLoginUser = findEntity(TUserApp.class, userId);
		if (appLoginUser == null) {
			throw new ValidateException("user.userUnExist");
		}
        List<Object> ObjectList = new ArrayList<Object>();
		
		//获取点过赞的活动
		Integer totalRows = getRegActivityNums(userId);
		if(totalRows==0){
			pager.setTotalPages(0);
			pager.setTotalRows(0);
			pager.setPageNo(1);
		}
		
		//设置总条数
		pager.setTotalRows(totalRows);
		//计算并设置总页数
		Integer pages=totalRows%pager.getPageSize()>0?pager.getTotalRows()/pager.getPageSize()+1:pager.getTotalRows()/pager.getPageSize();
		pager.setTotalPages(pages);
		
		//计算每次查询的开始与结束位置
		Integer startNum = (pager.getPageNo()-1)*pager.getPageSize();
		Integer endNum = startNum + pager.getPageSize();
		String likeSql_="select distinct t.activity_id from t_activity_appuser t where t.user_id = '"+userId+"' order by t.enroll_time desc   limit "+startNum+", "+endNum; 
		
		List<Map<String, Object>> listMap=this.jdbcTemplate.queryForList(likeSql_);
		if(listMap!=null && listMap.size()>0){
			for(int i=0;i<listMap.size();i++){
				TActivity act = null;
				
				String contentId = StringUtil.toString(listMap.get(i).get("activity_id"));
				
				act = findEntity(TActivity.class, contentId);
				if(act == null){
					continue;
				}
				
				act.setTypes("activity");
					
				//设置是否已经报过名
				Integer regNums = this.getRegActivityNumsById(userId, contentId);
				if(regNums>0){
					act.setRegFlag("yes");
				}else{
					act.setRegFlag("no");
				}
				//Add by Bing 2015-08-27  
				Criteria activityImageCriteria = getCriteria(TActivityImage.class);
				activityImageCriteria.add(Restrictions.eq("activityId", act.getId()));
				activityImageCriteria.addOrder(Order.asc("orderIndex"));
				act.setImageList(activityImageCriteria.list());
					
				act.setFlag(iActivityService.checkActivity(act.getId(), userId));
					
				String content = act.getDescription();
				if(content.contains(SysConstant.startString)&&content.contains(SysConstant.endString)){
					act.setVideoFlag("video");
				}else{
					act.setVideoFlag("notvideo");
				}
					
				//设置点赞数量   Add by Bing 2015-08-27  
				String likeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.delete_flag='0'";
				List<Map<String, Object>> listMapLike=this.jdbcTemplate.queryForList(likeSql);
				if(listMapLike!=null && listMapLike.size()>0){
					act.setLikeAmount(StringUtil.toInteger(listMapLike.get(0).get("num")));
				}else{
					act.setLikeAmount(0);
				}
					
				//设置当前用户是否对该信息点过赞  Add by Bing 2015-08-27  
				String islikeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.userId='"+userId+"' and t.delete_flag='0'";
				List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
				Integer amount=0;
				if(listMapIsLike!=null && listMapIsLike.size()>0){
					amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
				}else{
					amount=0;
				}
				if(amount>0){
					act.setLike(true);
				}else{
					act.setLike(false);
				}
					
				//设置浏览数量  Add by Bing 2015-08-27  
				act.setBrowseTimes(logService.getBrowseTimes(act.getId(), "activity", userId));
				
				//设置浏览数量(同一人浏览几次算几次)  Add by Bing 2015-08-27  
				act.setAllBrowseTimes(logService.getAllBrowseTimes(act.getId()+"", "activity", userId));
					
				//设置评论数量  Add by Bing 2015-08-27  
				act.setCommentAmount(commentsService.getCommentsAmount(act.getId()+"", "activity"));
					
				//设置Finish标志   Add by Bing 2015-08-27  
				long deadLine = act.getEndTime().getTime();
				long nowTime = new Date().getTime();
				if(nowTime>deadLine){
					act.setFinishFlag("true");
				}else{
					act.setFinishFlag("false");
				}
				
				if(act!=null){
					ObjectList.add(act);
				}
			}
		}
		return ObjectList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object getLikeArticles(String userId) throws Exception {
		if (StringUtils.isBlank(userId))
			throw new ValidateException("news.notIsLoginUser");

		TUserApp appLoginUser = findEntity(TUserApp.class, userId);
		if (appLoginUser == null) {
			throw new ValidateException("user.userUnExist");
		}
		
		List<Object> ObjectList = new ArrayList<Object>();
		
		String likeSql_="select distinct t.contentId,t.type from t_like t where t.delete_flag='0' and t.userId='"+userId+"' order by t.like_time desc limit 3";
		List<Map<String, Object>> listMap=this.jdbcTemplate.queryForList(likeSql_);
		if(listMap!=null && listMap.size()>0){
			for(int i=0;i<listMap.size();i++){
				TNews tnews = null;
				TActivity act = null;
				
				String type = StringUtil.toString(listMap.get(i).get("type"));
				String contentId = StringUtil.toString(listMap.get(i).get("contentId"));
				if("news".equals(type)){
					tnews = findEntity(TNews.class,Integer.parseInt(contentId));
					if(tnews == null){
						continue;
					}
					tnews.setTypes("new");
					
					//Add by Bing 2015-08-27  
					Criteria newsImageCriteria = getCriteria(TNewsImage.class);
					newsImageCriteria.add(Restrictions.eq("newsId",Integer.valueOf(contentId)));
					newsImageCriteria.addOrder(Order.asc("orderIndex"));
					tnews.setImageList(newsImageCriteria.list());
					
					//Add by Bing 2015-08-27  
					String content = StringUtil.toStringNoTrim(tnews.getContent());
					if(content.contains(SysConstant.startString)&&content.contains(SysConstant.endString)){
						tnews.setVideoFlag("video");
					}else{
						tnews.setVideoFlag("notvideo");
					}
					
					//设置点赞数量   Add by Bing 2015-08-27  
					String likeSql="select count(t.id) num from t_like t where  t.contentId='"+tnews.getNewsId()+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapLike=this.jdbcTemplate.queryForList(likeSql);
					if(listMapLike!=null && listMapLike.size()>0){
						tnews.setLikeAmount(StringUtil.toInteger(listMapLike.get(0).get("num")));
					}else{
						tnews.setLikeAmount(0);
					}
					
					//设置当前用户是否对该信息点过赞  Add by Bing 2015-08-27  
					String islikeSql="select count(t.id) num from t_like t where  t.contentId='"+tnews.getNewsId()+"' and t.userId='"+userId+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
					Integer amount=0;
					if(listMapIsLike!=null && listMapIsLike.size()>0){
						amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
					}else{
						amount=0;
					}
					if(amount>0){
						tnews.setLike(true);
					}else{
						tnews.setLike(false);
					}
					
					//设置浏览数量  Add by Bing 2015-08-27  
					tnews.setBrowseTimes(logService.getBrowseTimes(tnews.getNewsId()+"", "", userId));
					
					//设置浏览数量(同一人浏览几次算几次)  Add by Bing 2015-08-27  
					tnews.setAllBrowseTimes(logService.getAllBrowseTimes(tnews.getNewsId()+"", "", userId));
					
					//设置评论数量  Add by Bing 2015-08-27  
					tnews.setCommentAmount(commentsService.getCommentsAmount(tnews.getNewsId()+"", ""));
				}
				
				if("activity".equals(type)){
					act = findEntity(TActivity.class, contentId);
					if(act == null){
						continue;
					}
					//设置是否已经报过名
					Integer regNums = this.getRegActivityNumsById(userId, contentId);
					if(regNums>0){
						act.setRegFlag("yes");
					}else{
						act.setRegFlag("no");
					}
					
					act.setTypes("activity");
					//Add by Bing 2015-08-27  
					Criteria activityImageCriteria = getCriteria(TActivityImage.class);
					activityImageCriteria.add(Restrictions.eq("activityId", act.getId()));
					activityImageCriteria.addOrder(Order.asc("orderIndex"));
					act.setImageList(activityImageCriteria.list());
					
					act.setFlag(iActivityService.checkActivity(act.getId(), userId));
					
					String content = act.getDescription();
					if(content.contains(SysConstant.startString)&&content.contains(SysConstant.endString)){
						act.setVideoFlag("video");
					}else{
						act.setVideoFlag("notvideo");
					}
					
					//设置点赞数量   Add by Bing 2015-08-27  
					String likeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapLike=this.jdbcTemplate.queryForList(likeSql);
					if(listMapLike!=null && listMapLike.size()>0){
						act.setLikeAmount(StringUtil.toInteger(listMapLike.get(0).get("num")));
					}else{
						act.setLikeAmount(0);
					}
					
					//设置当前用户是否对该信息点过赞  Add by Bing 2015-08-27  
					String islikeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.userId='"+userId+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
					Integer amount=0;
					if(listMapIsLike!=null && listMapIsLike.size()>0){
						amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
					}else{
						amount=0;
					}
					if(amount>0){
						act.setLike(true);
					}else{
						act.setLike(false);
					}
					
					//设置浏览数量  Add by Bing 2015-08-27  
					act.setBrowseTimes(logService.getBrowseTimes(act.getId(), "activity", userId));
					
					//设置浏览数量(同一人浏览几次算几次)  Add by Bing 2015-08-27  
					act.setAllBrowseTimes(logService.getAllBrowseTimes(act.getId()+"", "activity", userId));
					
					//设置评论数量  Add by Bing 2015-08-27  
					act.setCommentAmount(commentsService.getCommentsAmount(act.getId()+"", "activity"));
					
					//设置Finish标志  Add by Bing 2015-08-27  
					long deadLine = act.getEndTime().getTime();
					long nowTime = new Date().getTime();
					if(nowTime>deadLine){
						act.setFinishFlag("true");
					}else{
						act.setFinishFlag("false");
					}
				}
				
				if(tnews!=null){
					ObjectList.add(tnews);
				}
				if(act!=null){
					ObjectList.add(act);
				}
			}
		}
		return ObjectList;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Object getAllLikeArticles(Pager pager, String userId) throws Exception {
		pager.setPageSize(10);
		if (StringUtils.isBlank(userId))
			throw new ValidateException("news.notIsLoginUser");

		TUserApp appLoginUser = findEntity(TUserApp.class, userId);
		if (appLoginUser == null) {
			throw new ValidateException("user.userUnExist");
		}
		
		List<Object> ObjectList = new ArrayList<Object>();
		
		//获取点过赞的活动、新闻的总数
		Integer totalRows = getLikeArticlesNums(userId);
		if(totalRows==0){
			pager.setTotalPages(0);
			pager.setTotalRows(0);
			pager.setPageNo(1);
		}
		
		//设置总条数
		pager.setTotalRows(totalRows);
		//计算并设置总页数
		Integer pages=totalRows%pager.getPageSize()>0?pager.getTotalRows()/pager.getPageSize()+1:pager.getTotalRows()/pager.getPageSize();
		pager.setTotalPages(pages);
		
		//计算每次查询的开始与结束位置
		Integer startNum = (pager.getPageNo()-1)*pager.getPageSize();
		Integer endNum = startNum + pager.getPageSize();//分页可能有问题，limit 2,4 代表从2开始，查询4条数据，而不是查2、3条数据
		String likeSql_="select count_cxb_sql_index.contentId, count_cxb_sql_index.type from ( select distinct t.contentId,t.type from t_like t where t.delete_flag='0' and  t.userId='"+userId+"' order by t.like_time desc ) as count_cxb_sql_index  limit "+startNum+", "+endNum; 
		
		List<Map<String, Object>> listMap=this.jdbcTemplate.queryForList(likeSql_);
		if(listMap!=null && listMap.size()>0){
			for(int i=0;i<listMap.size();i++){
				TNews tnews = null;
				TActivity act = null;
				
				String type = StringUtil.toString(listMap.get(i).get("type"));
				String contentId = StringUtil.toString(listMap.get(i).get("contentId"));
				if("news".equals(type)){
					tnews = findEntity(TNews.class,Integer.parseInt(contentId));
					if(tnews == null){
						continue;
					}
					tnews.setTypes("new");
					
					//Add by Bing 2015-08-27  
					Criteria newsImageCriteria = getCriteria(TNewsImage.class);
					newsImageCriteria.add(Restrictions.eq("newsId",Integer.valueOf(contentId)));
					newsImageCriteria.addOrder(Order.asc("orderIndex"));
					tnews.setImageList(newsImageCriteria.list());
					
					//Add by Bing 2015-08-27  
					String content = StringUtil.toStringNoTrim(tnews.getContent());
					if(content.contains(SysConstant.startString)&&content.contains(SysConstant.endString)){
						tnews.setVideoFlag("video");
					}else{
						tnews.setVideoFlag("notvideo");
					}
					
					//设置点赞数量   Add by Bing 2015-08-27  
					String likeSql="select count(t.id) num from t_like t where  t.contentId='"+tnews.getNewsId()+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapLike=this.jdbcTemplate.queryForList(likeSql);
					if(listMapLike!=null && listMapLike.size()>0){
						tnews.setLikeAmount(StringUtil.toInteger(listMapLike.get(0).get("num")));
					}else{
						tnews.setLikeAmount(0);
					}
					
					//设置当前用户是否对该信息点过赞 Add by Bing 2015-08-27  
					String islikeSql="select count(t.id) num from t_like t where  t.contentId='"+tnews.getNewsId()+"' and t.userId='"+userId+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
					Integer amount=0;
					if(listMapIsLike!=null && listMapIsLike.size()>0){
						amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
					}else{
						amount=0;
					}
					if(amount>0){
						tnews.setLike(true);
					}else{
						tnews.setLike(false);
					}
					
					//设置浏览数量  Add by Bing 2015-08-27  
					tnews.setBrowseTimes(logService.getBrowseTimes(tnews.getNewsId()+"", "", userId));
					
					//设置浏览数量(同一人浏览几次算几次)  Add by Bing 2015-08-27  
					tnews.setAllBrowseTimes(logService.getAllBrowseTimes(tnews.getNewsId()+"", "", userId));
					
					//设置评论数量  Add by Bing 2015-08-27  
					tnews.setCommentAmount(commentsService.getCommentsAmount(tnews.getNewsId()+"", ""));
				}
				
				if("activity".equals(type)){
					act = findEntity(TActivity.class, contentId);
					if(act == null){
						continue;
					}
					act.setTypes("activity");
					
					//设置是否已经报过名
					Integer regNums = this.getRegActivityNumsById(userId, contentId);
					if(regNums>0){
						act.setRegFlag("yes");
					}else{
						act.setRegFlag("no");
					}
					//Add by Bing 2015-08-27  
					Criteria activityImageCriteria = getCriteria(TActivityImage.class);
					activityImageCriteria.add(Restrictions.eq("activityId", act.getId()));
					activityImageCriteria.addOrder(Order.asc("orderIndex"));
					act.setImageList(activityImageCriteria.list());
					
					act.setFlag(iActivityService.checkActivity(act.getId(), userId));
					
					String content = act.getDescription();
					if(content.contains(SysConstant.startString)&&content.contains(SysConstant.endString)){
						act.setVideoFlag("video");
					}else{
						act.setVideoFlag("notvideo");
					}
					
					//设置点赞数量   Add by Bing 2015-08-27  
					String likeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapLike=this.jdbcTemplate.queryForList(likeSql);
					if(listMapLike!=null && listMapLike.size()>0){
						act.setLikeAmount(StringUtil.toInteger(listMapLike.get(0).get("num")));
					}else{
						act.setLikeAmount(0);
					}
					
					//设置当前用户是否对该信息点过赞  Add by Bing 2015-08-27  
					String islikeSql="select count(t.id) num from t_like t where t.type='activity' and t.contentId='"+act.getId()+"' and t.userId='"+userId+"' and t.delete_flag='0'";
					List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
					Integer amount=0;
					if(listMapIsLike!=null && listMapIsLike.size()>0){
						amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
					}else{
						amount=0;
					}
					if(amount>0){
						act.setLike(true);
					}else{
						act.setLike(false);
					}
					
					//设置浏览数量  Add by Bing 2015-08-27  
					act.setBrowseTimes(logService.getBrowseTimes(act.getId(), "activity", userId));
					
					//设置浏览数量(同一人浏览几次算几次)  Add by Bing 2015-08-27  
					act.setAllBrowseTimes(logService.getAllBrowseTimes(act.getId()+"", "activity", userId));
					
					//设置评论数量  Add by Bing 2015-08-27  
					act.setCommentAmount(commentsService.getCommentsAmount(act.getId()+"", "activity"));
					
					//设置Finish标志   Add by Bing 2015-08-27  
					long deadLine = act.getEndTime().getTime();
					long nowTime = new Date().getTime();
					if(nowTime>deadLine){
						act.setFinishFlag("true");
					}else{
						act.setFinishFlag("false");
					}
				}
				
				if(tnews!=null){
					ObjectList.add(tnews);
				}
				if(act!=null){
					ObjectList.add(act);
				}
			}
		}
		return ObjectList;
	}
	

	@Override
	public Object getShowMoreFlag(String userId, String type) throws Exception {
		Integer amount = 0;
		if("activity".equals(type)){
			amount = this.getRegActivityNums(userId);
		}else{
			amount = this.getLikeArticlesNums(userId);
		}
		if(amount>3){
			return "yes";
		}else{
			return "no";
		}
	}
	
	
	/**
	 * 查询用户点赞的新闻、活动的数量  Add by Bing 2015-08-27
	 * @param userId
	 * @return
	 */
	private Integer getLikeArticlesNums(String userId){
		
		String islikeSql="select count(distinct t.contentId) num from t_like t where t.delete_flag='0' and  t.userId='"+userId+"'";
		List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
		Integer amount=0;
		if(listMapIsLike!=null && listMapIsLike.size()>0){
			amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
		}else{
			amount=0;
		}
		return amount;
	}
	/**
	 * 查询用户报过名的活动的数量  Add by Bing 2015-08-27
	 * @param userId
	 * @return
	 */
	private Integer getRegActivityNums(String userId){
		String islikeSql="select count(distinct t.activity_id) num from t_activity_appuser t where t.user_id = '"+userId+"'";
		List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
		Integer amount=0;
		if(listMapIsLike!=null && listMapIsLike.size()>0){
			amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
		}else{
			amount=0;
		}
		return amount;
	}
	
	/**
	 * 查询用户是否对一个活动报名了  Add by Bing 2015-08-28
	 * @param userId
	 * @return
	 */
	private Integer getRegActivityNumsById(String userId,String activityId){
		String islikeSql="select count(distinct t.activity_id) num from t_activity_appuser t where t.activity_id='"+activityId+"' and  t.user_id = '"+userId+"'";
		List<Map<String, Object>> listMapIsLike=this.jdbcTemplate.queryForList(islikeSql);
		Integer amount=0;
		if(listMapIsLike!=null && listMapIsLike.size()>0){
			amount=StringUtil.toInteger(listMapIsLike.get(0).get("num"));
		}else{
			amount=0;
		}
		return amount;
	}
	
}
